package com.edu.neusoft.phone_sale.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.neusoft.phone_sale.common.ResponseResult;
import com.edu.neusoft.phone_sale.dto.ProductsDTO;
import com.edu.neusoft.phone_sale.entity.Products;
import com.edu.neusoft.phone_sale.service.ProductsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 产品表，存储产品的详细信息(Products)表控制层
 */
@RestController
@Slf4j
@Api(value = "app端手机展示", tags = "app端手机展示")
@RequestMapping("/api/products")
public class ProductsController {
    /**
     * 服务对象
     */
    @Autowired
    private ProductsService productsService;

    /**
     * 分页查询手机信息
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation("分页查询手机信息")
    @GetMapping("/page")
    public ResponseResult getByPage(@RequestParam int pageNum, @RequestParam int pageSize) {
        return ResponseResult.okResult(productsService.findByPage(pageNum, pageSize));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("{id}")
    public ResponseResult selectOne(@PathVariable("id") Integer id) {
        return ResponseResult.okResult(productsService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param products 实体对象
     * @return 新增结果
     */
    @ApiOperation("新增手机信息")
    @PostMapping
    public ResponseResult insert(@RequestBody Products products) {
        return ResponseResult.okResult(this.productsService.save(products));
    }

    /**
     * 修改数据
     *
     * @param products 实体对象
     * @return 修改结果
     */
    @ApiOperation("修改手机信息")
    @PutMapping
    public ResponseResult update(@RequestBody Products products) {
        return ResponseResult.okResult(this.productsService.updateById(products));
    }

    /**
     * 删除手机
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @ApiOperation("删除手机信息")
    @DeleteMapping
    public ResponseResult delete(@RequestParam("idList") List<Long> idList) {
        return ResponseResult.okResult(this.productsService.removeByIds(idList));
    }

}

